Skip to content

Add injectable APIRequestor to StripeClient#1837

Draft
ahoglund wants to merge 1 commit intomasterfrom
inject-api-requestor
Draft

Add injectable APIRequestor to StripeClient#1837
ahoglund wants to merge 1 commit intomasterfrom
inject-api-requestor

Conversation

@ahoglund
Copy link
Copy Markdown

@ahoglund ahoglund commented Mar 26, 2026

Why?

Platform engineers need to swap the HTTP transport in StripeClient — e.g., routing requests through an internal gRPC API gateway instead of Net::HTTP, or wanting to use a different http library.

Today, StripeClient hardcodes APIRequestor.new(config) with no extension point, and the actual HTTP call is buried inside a private method with no override seam. This PR adds the minimal scaffolding to make the transport pluggable without forking the client.

What?

  • Added a requestor: kwarg to StripeClient#initialize that accepts a factory callable (StripeConfiguration) -> APIRequestor, with validation that the returned instance is an APIRequestor
  • Extracted a protected send_request method on APIRequestor as the subclass override point for transport, replacing the inline connection_manager.execute_request call
  • Wrapped execute_request and execute_request_stream with an active_requestor save/restore pattern so that nested operations (generated resource methods, save, etc.) resolve the custom requestor via thread-local lookup
  • Added tests covering factory callable, validation, transport override end-to-end, and active_requestor propagation/restoration
  • Updated Sorbet type signatures in rbi/stripe/stripe_client.rbi

See Also

This is PR 1 of 2. A follow-up PR will extract retry/error seams (should_retry?, sleep_time, network_error_map) as overridable instance methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants